﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Presentation.Web.MVC.Client.Controllers;
using Infraestructure.CrossCutting.Caching;
using Infraestructure.CrossCutting.IoC;
using Domain.MainModule.Entities;

namespace Presentation.Web.MVC.Client.ViewUserControl
{
    public class UserViewUserControl<T>: 
        System.Web.Mvc.ViewUserControl<T> where T: Domain.MainModule.Entities.User
    {
        private ICacheManager _cacheManager;

        public UserViewUserControl()
        {
            _cacheManager = IoCFactory.Instance.CurrentContainer.Resolve<ICacheManager>();
        }

        public SelectList CountriesSelectList
        {
            get
            {
                object result;
                result = _cacheManager.GetData(Resources.CacheKeys.Country);
                if (result == null)
                {
                    _cacheManager.StoreData(Resources.CacheKeys.Country, new SelectList(CommonController.Countries, "CountryId", "Name"));
                    result = _cacheManager.GetData(Resources.CacheKeys.Country);
                }
                return (SelectList)result;
            }
        }

        public SelectList GendersSelectList
        {
            get
            {
                object result;
                result = _cacheManager.GetData(Resources.CacheKeys.Gender);
                if (result == null)
                {
                    _cacheManager.StoreData(Resources.CacheKeys.Gender, new SelectList(CommonController.Genders, "GenderId", "Description"));
                    result = _cacheManager.GetData(Resources.CacheKeys.Gender);
                }
                return (SelectList)result;
            }
        }

        public SelectList MaritalStatusSelectList
        {
            get
            {
                object result;
                result = _cacheManager.GetData(Resources.CacheKeys.MaritalStatus);
                if (result == null)
                {
                    _cacheManager.StoreData(Resources.CacheKeys.MaritalStatus, new SelectList(CommonController.Genders, "GenderId", "Description"));
                    result = _cacheManager.GetData(Resources.CacheKeys.MaritalStatus);
                }
                return (SelectList)result;
            }
        }

        public List<Address> GetAddress(Guid UserId)
        {
            return CommonController.GetAddresses(UserId);
        }

        public List<Phone> GetPhones(Guid UserId)
        {
            return CommonController.GetPhones(UserId);
        }

        public List<Identity> GetIdentities(Guid UserId)
        {
            return CommonController.GetIdentities(UserId);
        }
        
        public List<VirtualAccount> GetVirtualAccounts(Guid UserId)
        {
            return CommonController.GetVirtualAccounts(UserId);
        }

        public List<CreditCard> GetCreditCards(Guid UserId)
        {
            return CommonController.GetCreditCards(UserId);
        }
    }
}